﻿<%@ WebHandler Language="C#" Class="Forms" %>

using System;
using System.Web;
using System.Configuration;
using System.Linq;

public class Forms : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        AjaxResponse axresponse = new AjaxResponse();
        context.Response.ContentType = "application/json";
        string action = AHMIDEAFunctions.ContextPostData(context, "action").ToUpper();
        string appid = AHMIDEAFunctions.ContextPostData(context, "appid");
        string formid = AHMIDEAFunctions.ContextPostData(context, "formid");
        string state = AHMIDEAFunctions.ContextPostData(context, "state");
        //TYPE = 1:history; 2:favorite; 3:save states
        
        switch (action)
        {
            case "GETSTATE":
                context.Response.ContentType = "text/html";
                context.Response.Write(AHMIDEAFunctions.GetFormState(context, appid, formid));
                break;
            case "CHECKSTATE":
                context.Response.Write(AHMIDEAFunctions.CheckFormState(context, appid, formid));
                break;

            case "ADDSTATE":
                axresponse = AHMIDEAFunctions.SaveFormState(context, appid, formid, state);
                context.Response.Write(axresponse.GenerateJSON());
                break;
            case "DELSTATE":
                axresponse = AHMIDEAFunctions.DeleteFormState(context, appid, formid);
                context.Response.Write(axresponse.GenerateJSON());
                break;
            case "ADDFAV":
                axresponse = AHMIDEAFunctions.SaveFormFavorite(context, appid, formid);
                context.Response.Write(axresponse.GenerateJSON());
                break;
            case "DELFAV":
                axresponse = AHMIDEAFunctions.DeleteFormFavorite(context, appid, formid);
                context.Response.Write(axresponse.GenerateJSON());
                break;
            default:
                axresponse.Status = "0";
                context.Response.Write(axresponse.GenerateJSON());
                break;

        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }


}